package com.project2.controller;

import com.project2.bean.ResultVo;
import com.project2.bean.po.MarketUser;
import com.project2.bean.vo.OrderStatusVo;
import com.project2.bean.vo.UserIndex;
import com.project2.service.UserIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author ：HsDsg
 * @date ：2022/8/15 13:09
 * @description：TODO
 */
@RestController
@RequestMapping("wx/user")
public class WxUserController {

    @Autowired
    UserIndexService indexService;

    @RequestMapping("index")
    public ResultVo userIndex(HttpServletRequest request){
        String header = request.getHeader("X-CskaoyanMarket-Token");
        MarketUser user = (MarketUser) request.getSession().getAttribute(header);

        if (user==null){
            return ResultVo.ok("请登入",501);
        }

        UserIndex userIndex = indexService.selectUserOrder(user);

        OrderStatusVo orderStatusVo = new OrderStatusVo();
        orderStatusVo.setOrder(userIndex);

        return ResultVo.ok(orderStatusVo);
    }
}
